home *** CD-ROM | disk | FTP | other *** search
- //Web page retrieval with Sweeper Internet and Http functions (from
- SurfBear sample)
-
- //
- // This is where all of the actually Internet work is done.
- //
- UINT CInternetThread::_GetPageWorker()
- {
- UINT uiResult = THREAD_BAD;
-
- if (m_hSession == NULL)
- {
- //
- // Initialize the Internet Functions.
- //
- TRACE("Starting Session (Access = %i) (Proxy = %s)\r\n",
- GetAccessTypeIndex(),
- (LPCTSTR)m_strProxyServer) ;
- m_hSession = ::InternetOpen("MSDN SurfBear",
- m_dwAccessType,
- m_strProxyServer,
- INVALID_PORT_NUMBER,
- 0 ) ;
-
- if (!Succeeded(m_hSession, "InternetOpen"))
- {
- // Send message to UI that we finished.
- ::PostMessage(m_hPostMsgWnd,WM_READFILECOMPLETED, NULL,
- (LPARAM)THREAD_BAD) ;
-
- return THREAD_BAD;
- }
- }
-
- HINTERNET hConnect = ::InternetConnect(m_hSession,
- m_strServer,
- INVALID_PORT_NUMBER,
- "",
- "",
- INTERNET_SERVICE_HTTP,
- 0,
- 0) ;
-
-
- if (Succeeded(hConnect, "InternetConnect"))
- {
-
- HINTERNET hHttpFile = ::HttpOpenRequest(hConnect,
- "GET",
- m_strPath,
- HTTP_VERSION,
- "",
- 0,
- INTERNET_OPEN_FLAG_NO_CACHE,
- 0) ;
-
- if (Succeeded(hHttpFile, "HttpOpenRequest"))
- {
-
- BOOL bSendRequest = ::HttpSendRequest(hHttpFile, "", 0, 0, 0);
-
- if (Succeeded((HINTERNET)bSendRequest, "HttpSendRequest"))
- {
- // Get size of file.
- char bufQuery[32] ;
- DWORD dwFileSize ;
- DWORD dwLengthBufQuery = sizeof (bufQuery);
- BOOL bQuery = ::HttpQueryInfo(hHttpFile,
- HTTP_QUERY_CONTENT_LENGTH,
- bufQuery,
- &dwLengthBufQuery) ;
- if (Succeeded((HINTERNET)bQuery, "HttpQueryInfo"))
- {
- // The Query was successful, so allocate the memory.
- TRACE("HttpQueryInfo FileSize is %s.\r\n", bufQuery) ;
- dwFileSize = (DWORD)atol(bufQuery) ;
- }
- else
- {
- // The Query failed. Allocate some memory. Should
- allocate memory in blocks.
- TRACE("\tQueryInfo Failed. Just get 5k.\r\n") ;
- dwFileSize = 5*1024 ;
- }
-
- ASSERT(m_buffer == NULL);
- m_buffer = new char[dwFileSize+1] ;
- DWORD dwBytesRead ;
- BOOL bRead = ::InternetReadFile(hHttpFile,
- m_buffer,
- dwFileSize+1,
- &dwBytesRead);
- if (Succeeded((HINTERNET)bRead, "InternetReadFile"))
- {
- TRACE("\tBytes Read is %d\r\n", dwBytesRead) ;
- m_buffer[dwBytesRead] = 0 ;
- uiResult = THREAD_GOOD;
- } // InternetReadFile
- } // HttpSendRequest
-
- VERIFY(::InternetCloseHandle(hHttpFile));
- } // HttpOpenRequest
-
- VERIFY(::InternetCloseHandle(hConnect)) ;
- } // InternetConnect
-
- ::PostMessage(m_hPostMsgWnd,WM_READFILECOMPLETED, NULL, (LPARAM)uiResult) ;
-
- return uiResult ;
- }
-
- ///Web page, ftp file, or gopher file retrieval with Sweeper URL
- Moniker (from Progress sample)
-
- //
- -----------------------------------------------------------------------
- --- -
- // %%Function: CDownload::DoDownload
- //
- -----------------------------------------------------------------------
- --- -
- HRESULT
- CDownload::DoDownload(HWND hwndStatus, HWND hwndProgress, HWND hwndText)
- {
- HRESULT hr = CreateURLMoniker(NULL, m_url, &m_pmk);
-
- if( SUCCEEDED(hr) )
- {
- m_pbsc = new CBindStatusCallback(hwndStatus, hwndProgress, hwndText);
- if (m_pbsc != NULL)
- m_pbsc->AddRef();
- else
- hr = E_OUTOFMEMORY;
- }
-
- if (SUCCEEDED(hr))
- hr = CreateBindCtx(0, &m_pbc);
-
- if (SUCCEEDED(hr))
- hr = m_pbc->RegisterObjectParam(OLESTR("BindStatusCallback"), m_pbsc);
-
- IStream* pstm;
- if (SUCCEEDED(hr))
- hr = m_pmk->BindToStorage(m_pbc, 0, IID_IStream, (void**)&pstm);
-
- return hr;
- } // CDownload::DoDownload
-